import express from "express";
import UserService from "../../../service/api/userService";
import { success } from "../common";
const router: any = express.Router();

/**
* @api {get} /api/user/info 用户信息
* @apiVersion 1.0.0
* @apiName 用户信息
* @apiGroup 用户
* @apiDescription 返回用户详细信息
* @apiSuccess {Number} code 1
* @apiSuccess {Object} data 用户信息
*/
router.get("/infos", async function (req: any, res: any, next: any) {
  const userDb = new UserService();
  const data = await userDb.list();
  success(data, res);
});
  /**
    * @api {post} /api/user/edit 修改用户
    * @apiVersion 1.0.0
    * @apiName 修改用户
    * @apiGroup 用户
    * @apiPermission authenticated user
    * @apiParam (Request body) {String} name 要改的字段
    * @apiExample {js} Example usage:
    * const data = {
    *   "name": "Do the dishes",
    *    'avatar':'头像'
    * }
    *
    * $http.defaults.headers.common["Authorization"] = token;
    * $http.post(url, data)
    *   .success((res, status) => doSomethingHere())
    *   .error((err, status) => doSomethingHere());
    *
    * @apiSuccess (Success 200) {String} code 成功是1，失败是0
    * @apiSuccess (Success 200) {Object} data
    *
    * @apiSuccessExample {json} Success response:
    *     {
    *       code:1,
    *      "data": {
    *         userId:''
    *       },
    *    }
    *
    * @apiUse UnauthorizedError
    */
router.post("/edit", async function (req: any, res: any, next: any) {
  const userDb = new UserService();
  const data = await userDb.list();
  success(data, res);
});


export default router;
